package com.itheima.wisdomnext.service.ImpI;

import com.itheima.wisdomnext.entity.QaPost;
import com.itheima.wisdomnext.entity.Result.enumcalss.ErrorCode;
import com.itheima.wisdomnext.mapper.QATextAnswerMapper;
import com.itheima.wisdomnext.service.QATextAnswerService;
import com.itheima.wisdomnext.util.QATextAnswerS_Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QATextAnswerServiceImpl implements QATextAnswerService {

    @Autowired
    private QATextAnswerMapper qaTextAnswerMapper;

    // 实现保存自由回答的方法
    @Override
    public int saveAnswer(QaPost qaPost) {
        int i = qaTextAnswerMapper.insertAnswer(qaPost);
        if(i <= 0){
            QATextAnswerS_Util.isTrue(true, ErrorCode.FAILED,"保存自由回答失败");
        }
        return i;
    }

    // 实现保存选项式回答的方法
    @Override
    public int saveChoiceAnswer(Integer questionId, Integer answerUserId, Integer optionId) {
        int i = qaTextAnswerMapper.insertChoiceAnswer(questionId, answerUserId, optionId);
        if(i <= 0){
            QATextAnswerS_Util.isTrue(true,ErrorCode.FAILED,"保存选项式回答失败");
        }
        return i;
    }
}
